import hashlib
from base64 import b64encode
import rsa


def md5(content):
    content = str(content).encode()  # 转成字节

    value = hashlib.md5(content).hexdigest()  # 转成字符串
    return value


def bs64(content):
    content = str(content).encode()  # 转成字节

    value = b64encode(content).decode()  # 转成字符串
    return value


def rsa_jiami(content):
    content = str(content).encode()  # 转成字节

    key = rsa.PublicKey.load_pkcs1(open("data/public.pem", "rb").read())  # 加载加密字节

    value = rsa.encrypt(content, key)  # 也是字符串，进行加密数学运算
    value_rsa = b64encode(value).decode()  # 字节通过b64之后，转成字符串

    return value_rsa
